package com.ruoyi.web.controller.product_category;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.product_category.domain.Product_category;
import com.ruoyi.product_category.service.IProduct_categoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 商品分类区Controller
 * 
 * @author 张富饶
 * @date 2025-05-18
 */
@RestController
@RequestMapping("/product_category/product_category")
public class Product_categoryController extends BaseController
{
    @Autowired
    private IProduct_categoryService product_categoryService;

    /**
     * 查询商品分类区列表
     */
    @PreAuthorize("@ss.hasPermi('product_category:product_category:list')")
    @GetMapping("/list")
    public TableDataInfo list(Product_category product_category)
    {
        startPage();
        List<Product_category> list = product_categoryService.selectProduct_categoryList(product_category);
        return getDataTable(list);
    }

    /**
     * 导出商品分类区列表
     */
    @PreAuthorize("@ss.hasPermi('product_category:product_category:export')")
    @Log(title = "商品分类区", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Product_category product_category)
    {
        List<Product_category> list = product_categoryService.selectProduct_categoryList(product_category);
        ExcelUtil<Product_category> util = new ExcelUtil<Product_category>(Product_category.class);
        util.exportExcel(response, list, "商品分类区数据");
    }

    /**
     * 获取商品分类区详细信息
     */
    @PreAuthorize("@ss.hasPermi('product_category:product_category:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(product_categoryService.selectProduct_categoryById(id));
    }

    /**
     * 新增商品分类区
     */
    @PreAuthorize("@ss.hasPermi('product_category:product_category:add')")
    @Log(title = "商品分类区", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Product_category product_category)
    {
        return toAjax(product_categoryService.insertProduct_category(product_category));
    }

    /**
     * 修改商品分类区
     */
    @PreAuthorize("@ss.hasPermi('product_category:product_category:edit')")
    @Log(title = "商品分类区", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Product_category product_category)
    {
        return toAjax(product_categoryService.updateProduct_category(product_category));
    }

    /**
     * 删除商品分类区
     */
    @PreAuthorize("@ss.hasPermi('product_category:product_category:remove')")
    @Log(title = "商品分类区", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(product_categoryService.deleteProduct_categoryByIds(ids));
    }
}
